var t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), e = require("../../../@babel/runtime/helpers/asyncToGenerator"), a = getApp();

Page({
    data: {
        posterFlag: !1,
        explainFlag: !1,
        agreement: !1,
        evaluationData: {},
        poster_url: ""
    },
    onLoad: function(t) {
        var e = t.health_id;
        this.getData(e), this.getPoste(e);
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getData: function(t) {
        var e = this, n = a.getNetAddresss("plugin.health-assessment.api.index.getData");
        a._postNetWork({
            url: n,
            showToastIn: !0,
            data: {
                health_id: t,
                art: "getEvaluation"
            },
            success: function(t) {
                var a = t.data;
                1 == a.result ? (console.log(a.data.getEvaluation.top), e.setData({
                    evaluationData: a.data.getEvaluation.top
                })) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    onChange: function(t) {
        this.setData({
            agreement: t.detail
        });
    },
    gotoRecord: function() {
        wx.navigateTo({
            url: "/packageE/healthy/healthyRecord/healthyRecord"
        });
    },
    setPosterFlag: function() {
        this.setData({
            posterFlag: !this.data.posterFlag
        });
    },
    setExplainFlag: function() {
        this.setData({
            explainFlag: !this.data.explainFlag
        });
    },
    gotoPaper: function() {
        var t = this.data.evaluationData;
        return 1 == t.is_evaluation ? (wx.showToast({
            icon: "none",
            title: "你好，本周你已测评过了",
            duration: 1500
        }), !1) : 1 != t.is_evaluation_agreement || this.data.agreement ? (console.log(t), 
        void wx.navigateTo({
            url: "/packageE/healthy/healthyPaper/healthyPaper?health_id=" + t.health_id
        })) : (wx.showToast({
            icon: "none",
            title: "请先阅读同意测评协议",
            duration: 1500
        }), !1);
    },
    getPoste: function(t) {
        var e = this, n = a.getNetAddresss("plugin.health-assessment.api.index.getData");
        a._postNetWork({
            url: n,
            data: {
                art: "getPoster",
                health_type: "1",
                health_id: t
            },
            success: function(t) {
                var a = t.data;
                1 == a.result && e.setData({
                    poster_url: a.data.getPoster.url_path
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    checkWritePotosAlbum: function() {
        var a = this;
        return e(t.default.mark(function e() {
            var n;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return n = a, t.next = 3, a.getAuthSetting("scope.writePhotosAlbum");

                  case 3:
                    if (t.sent) {
                        t.next = 7;
                        break;
                    }
                    return wx.showModal({
                        title: "请开启授权",
                        content: "是否跳转设置页开启授权",
                        success: function(t) {
                            t.confirm ? wx.openSetting({
                                success: function(t) {
                                    t.authSetting["scope.writePhotosAlbum"] ? n.saveImg() : console.log("还是没授权");
                                }
                            }) : t.cancel && console.log("用户点击取消");
                        }
                    }), t.abrupt("return");

                  case 7:
                    a.saveImg();

                  case 8:
                  case "end":
                    return t.stop();
                }
            }, e);
        }))();
    },
    saveImg: function() {
        var t = this;
        console.log("执行");
        var e = this.data.poster_url;
        wx.downloadFile({
            url: e,
            success: function(e) {
                console.log(e), wx.saveImageToPhotosAlbum({
                    filePath: e.tempFilePath,
                    success: function(e) {
                        wx.showToast({
                            title: "保存成功",
                            icon: "none",
                            duration: 2e3
                        }), t.setPosterFlag();
                    },
                    fail: function(t) {
                        console.log(t);
                    }
                });
            }
        });
    },
    getAuthSetting: function(t) {
        return new Promise(function(e, a) {
            wx.getSetting({
                success: function(a) {
                    a.authSetting[t] ? e(!0) : wx.authorize({
                        scope: t,
                        success: function() {
                            e(!0);
                        },
                        fail: function() {
                            e(!1);
                        }
                    });
                },
                fail: function() {
                    e(!1);
                }
            });
        });
    }
});